<?php

namespace app\admin\model\goods;

use think\Model;


class Goods extends Model
{

    

    

    // 表名
    protected $name = 'goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'switch_text',
        'is_hot_text',
        'is_new_text',
        'is_recommend_text',
        'spec_type_text',
        'create_time_text',
        'update_time_text',
        'delete_time_text'
    ];
    

    
    public function getSwitchList()
    {
        return ['0' => __('Switch 0'), '1' => __('Switch 1')];
    }

    public function getIsHotList()
    {
        return ['0' => __('Is_hot 0'), '1' => __('Is_hot 1')];
    }

    public function getIsNewList()
    {
        return ['0' => __('Is_new 0'), '1' => __('Is_new 1')];
    }

    public function getIsRecommendList()
    {
        return ['0' => __('Is_recommend 0'), '1' => __('Is_recommend 1')];
    }

    public function getSpecTypeList()
    {
        return ['0' => __('Spec_type 0'), '1' => __('Spec_type 1')];
    }


    public function getSwitchTextAttr($value, $data)
    {
        $value = $value ?: ($data['switch'] ?? '');
        $list = $this->getSwitchList();
        return $list[$value] ?? '';
    }


    public function getIsHotTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_hot'] ?? '');
        $list = $this->getIsHotList();
        return $list[$value] ?? '';
    }


    public function getIsNewTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_new'] ?? '');
        $list = $this->getIsNewList();
        return $list[$value] ?? '';
    }


    public function getIsRecommendTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_recommend'] ?? '');
        $list = $this->getIsRecommendList();
        return $list[$value] ?? '';
    }


    public function getSpecTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['spec_type'] ?? '');
        $list = $this->getSpecTypeList();
        return $list[$value] ?? '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['create_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['update_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDeleteTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['delete_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDeleteTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
